package com.nut.course.api.biz;

import com.nut.course.api.resp.UserAuth;
import com.nut.course.common.Result;
import com.nut.course.service.UserService;
import com.nut.course.util.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 鉴权服务
 */
@RestController
@RequestMapping("/")
@Validated
@Slf4j
public class AuthController {

    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public Result<UserAuth> login(@RequestParam String code, @RequestParam String state,
                                  HttpServletRequest request) {
        log.info("login_req_params,code={},state={}", code, state);
        String ip = IpUtil.client(request);
        log.info("ip=" + ip);
        return userService.login(code, state);
    }

    @RequestMapping("checkToken")
    public Result<String> checkToken() {
        return Result.ok();
    }

    //TODO 注销登录 logout

}
